<?php

namespace app\admin\controller\finance;

use app\admin\model\UM as UM;
use app\admin\service\CompanyBillService;
use ShidianUtil\Thinkphp\Response\ApiResponse;
use think\APP;
use think\Request as Request;

/**
 * CompanyBill 控制器
 * Class CompanyBill
 * @package app\admin\controller\finance;
 * @link https://www.kancloud.cn/manual/thinkphp6_0/1037509
 * @see \app\admin\validate\finance\CompanyBill
 */
class CompanyBill
{
    // 请求参数
    private Request $request;

    // service
    private CompanyBillService $service;

    public function __construct(Request $request, CompanyBillService $companyBillService)
    {
        $this->request = $request;
        $this->service = $companyBillService;
    }

    /**
     * 公司消费记录
     * @param UM|null $user
     * @return ApiResponse
     * @url /finance/company_bill/index
     */
    public function index(UM $user): ApiResponse
    {
        $request = $this->request;

        $companyId = $request->param('companyId');
        $startTime = $request->param('startTime');
        $endTime = $request->param('endTime');
        $page = $request->param('page', 1);
        $page_size = $request->param('page_size', 20);

        return ApiResponse::success($this->service->index($user, $companyId, $startTime, $endTime, $page, $page_size));
    }

}
